package com.yanqu.road.server.cmd.activity.stronghold.wild;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.Map;

@Cmd(code = GameProtocol.S_STRONGHOLD_WAR_MEMBER_ITEM_DONATE, desc = "成员道具捐献详情")
public class GetStrongholdMemberItemDonateDataCmd extends AbstractCommand {
    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.StrongholdMemberItemDonateDataReqMsg req = StrongholdWarProto.StrongholdMemberItemDonateDataReqMsg.parseFrom(packet.getBytes());
        type = req.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = StrongholdActivityMgr.getOpenActivityInfo();
        if (activityInfo == null) {
            return;
        }
        String unionUid = player.getUserInfo().getUnionUid();

     /*   StrongholdWarProto.StrongholdMemberItemDonateDataRespMsg.Builder resp = StrongholdWarProto.StrongholdMemberItemDonateDataRespMsg.newBuilder();
        Map<Long, Integer> dataMap = StrongholdWarMgr.getMemberItemDonateList(activityInfo.getActivityId(), unionUid, type);
        for (Map.Entry<Long, Integer> entry : dataMap.entrySet()) {
            Long userId = entry.getKey();
            Integer value = entry.getValue();
            StrongholdWarProto.ItemDonateDataMsg.Builder msg = StrongholdWarProto.ItemDonateDataMsg.newBuilder();
            msg.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(UserMgr.getUserBaseInfo(userId, GameServer.getInstance().getServerId())));
            msg.setValue(String.valueOf(value));
            resp.addData(msg);
        }
        player.sendChannelPacket(ClientProtocol.U_STRONGHOLD_WAR_MEMBER_ITEM_DONATE, resp);*/
        StrongholdWarCrossProto.StrongholdCrossDonateItemDetailReqMsg.Builder msg = StrongholdWarCrossProto.StrongholdCrossDonateItemDetailReqMsg.newBuilder();
        msg.setActivityId(activityInfo.getActivityId());
        msg.setUnionId(unionUid);
        msg.setType(type);
        player.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_STRONGHOLD_DONATE_ITEM_DETAIL, msg, msg.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
